import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '@/views/layout/index.vue'

// 外网路由
const Categary = () => import('../views/out/categary/index.vue');
const Index = () => import('../views/out/index.vue')
const Goal = () => import('../views/out/goal/index.vue')
const Plan = () => import('../views/out/plan/index.vue')
const Culture = () => import('../views/out/index.vue')
Vue.use(VueRouter)


const routes = [
    {
        path: '/',
        // 重定向到内网首页
        redirect: '/index'
    },
    {
        path: '/index',
        name: '首页',
        component: Index,
        redirect: '/categary',
        children: [
            {
                path: '/categary',
                name: 'categary',
                component: Categary
            },
            {
                path: '/plan',
                name: 'plan',
                component: Plan
            },
            {
                path: '/goal',
                name: 'goal',
                component: Goal
            },
            {
                path: '/culture',
                name: 'culture',
                component: Culture
            }
        ]
    },
    {
        path: '/inside/layout',
        component: Layout,
        children: [{

            path: '/inside/home',
            name: 'home',
            component: () =>
                import('@/views/inside/home')
        },
        {
            path: '/inside/mine',
            name: 'mine',
            component: () =>
                import('@/views/inside/mine')
        }, {
            path: '/inside/article',
            name: 'article',
            component: () =>
                import('@/views/inside/article')
        }, {
            path: '/inside/exchange',
            name: 'exchange',
            component: () =>
                import('@/views/inside/exchange')
        }, {
            path: '/inside/plan',
            name: 'plan',
            component: () =>
                import('@/views/inside/plan')
        },
        {
            path: '/inside/signIn',
            name: 'signIn',
            component: () =>
                import('@/views/inside/signIn')
        },
        {
            path: '/inside/about',
            name: 'about',
            component: () =>
                import('@/views/inside/about')
        },
        {
            path: '/inside/creation',
            name: 'creation',
            component: () =>
                import('@/views/inside/creation/all'),
        },
        {
            path: '/inside/creation/details/:articleId',
            name: 'details',
            component: () =>
                import('@/views/inside/creation/details'),
            props: true
        },
        {
            path: '/inside/edit/:articleId',
            name: 'edit',
            component: () =>
                import('@/views/inside/creation/edit'),
            props: true

        },
        {
            path: '/inside/creation/publish',
            name: 'publish',
            component: () =>
                import('@/views/inside/creation/publish'),
            props: true
        },
        {
            path: '/inside/creation/personItem',
            name: 'personItem',
            component: () =>
                import('@/views/inside/creation/personItem'),
            props: true
        },
        {
            path: '/inside/drashcard',
            name: 'drashcard',
            component: () =>
                import('@/views/inside/drashcard')
        },

        ]

    },
    {
        path: '/',
        redirect: '/login'
    },
    {
        path: '/login',
        name: 'login',
        component: () =>
            import('@/views/out/login')
    }
]

const router = new VueRouter({
    routes
})
// 路由导航

router.beforeEach((to, from, next) => {
    const user = JSON.parse(window.localStorage.getItem('user'))
    if (to.path.startsWith('/inside')) {
        if (user) {
            next()
        } else {
            next('/login')
        }
    } else {
        next()
    }
})
export default router
